<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');

JHtml::_('behavior.framework');

// Create some shortcuts.
$params		= &$this->item->params;
$n			= count($this->items);
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));

// check for at least one editable article
$isEditable = false;
if (!empty($this->items))
{
	foreach ($this->items as $article)
	{
		if ($article->params->get('access-edit'))
		{
			$isEditable = true;
			break;
		}
	}
}

?>





<div class="container noticias">
	
	<?php 
		$obj = null;
		foreach ($this->items as $item) :
			$obj = $item;
		endforeach;
		
		if(isset($obj)):		
			if($this->escape($obj->category_title) == 'Notícias' ) :  
				echo "<h3>Últimas Notícias</h3>";
			elseif($this->escape($obj->category_title) == 'Comissões Permanentes' ||
					$this->escape($obj->category_title) == 'Comissões Temporárias') :  
				echo "<h3>Atividade Legislativa</h3>";				
			else:
				echo "<h3>".$this->escape($obj->category_title)."</h3>";
			endif;
		endif;
	
	?>
	<div id="menuinterno"></div>
	
	
	<?php

		
		if($this->escape($obj->category_title) != 'Notícias' &   $this->escape($obj->category_title) != 'Câmara Itinerante') : 
			echo '<div class="content">';
			echo '<h4 class="title">';
	 		if($obj->parent_title != 'ROOT'):
	 			echo $this->escape($obj->category_title) ;
	 		endif;	
	 		
			if($this->escape($obj->category_title) == "Memória do Legislativo"):
				echo $this->escape($obj->category_title);
			elseif($this->escape($obj->category_title) != 'Comissões Permanentes' &
			   $this->escape($obj->category_title) != 'Comissões Temporárias') :
	 			echo ' - ' . $obj->title.'';
	 		endif;
	 		
	 		echo '</h4></div>';
		endif;
		
	?>
	
	<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
	<?php if ($this->params->get('show_headings') || $this->params->get('filter_field') != 'hide' || $this->params->get('show_pagination_limit')) :?>
	<fieldset >
		<?php if ($this->params->get('filter_field') != 'hide') :?>
			<table >
				<tr>
					<td>
						<label class="" for="filter-search">
					Busca por palavra-chave</label>
					</td>
					<td>
				<label  for="filter-date">	Data</label>
					</td>
				</tr>
				<tr>
					<td>				
					<input type="text" name="filter-search" id="filter-search" value="<?php echo $this->escape($this->state->get('list.filter')); ?>" class="inputbox title"   placeholder="<?php echo JText::_('COM_CONTENT_'.$this->params->get('filter_field').'_FILTER_LABEL'); ?>" />
					</td>
					<td>
					
					<?php
					
					if($this->state->get('filter.date')):
						$data = getDateMyFormat2($this->state->get('filter.date'));
					endif;
					?>
					<input type="text" name="filter-date" id="filter-date" value="<?php echo $data; ?>" class="inputbox"   placeholder="Formato: dd/mm/aaaa" />
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><a href="javascript:void(0)" onclick="document.adminForm.submit();" title="Pesquisar"><img src="<?php echo JUri::base() ?>templates/cmmacae/img/btnPesquisar.png" /></a></td>
				</tr>
			</table>
				
					
		<?php endif; ?>
		

		<input type="hidden" name="filter_order" value="" />
		<input type="hidden" name="filter_order_Dir" value="" />
		<input type="hidden" id="limitstart" name="limitstart" value="" />
		<input type="hidden" name="task" value="" />
	</fieldset>
	<?php endif; 
	
	
	?>
</form>
	
	<?php 

	$strHtml ='<div ';
	
	if(isset($obj)):		
		if($this->escape($obj->category_title) == 'Notícias') :  ?>
				
		<ul class="noticia">	
		<?php 
			$data='';
			$i=0;
			foreach ($this->items as $item) :  
				$hora = substr($item->publish_up, 11, 5);
				
				if($data != substr($item->publish_up, 0, 10)):		
					echo '<li class="data ';
					if($i==0):
						echo 'outros1 ';
					else:
						echo ' outros ';
					endif;
					echo '">' . getDateMyFormat(substr($item->publish_up, 0, 10)) . '</li>';
					
				endif;
				
				echo '<li><span>'. $hora .'</span><a href="' . JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)) . '" title="'.$item->title.'" >'.$item->title.'</a></li>';
				
				$data = substr($item->publish_up, 0, 10);
				$i++;
			endforeach;
		?>
	</ul>
	<?php 
		elseif($this->escape($obj->category_title) == 'Comissões Permanentes' ||
			   $this->escape($obj->category_title) == 'Comissões Temporárias') :
			$strHtml .= 'class="comissao-permanente">';
			$strHtml .= '<ul>';
			foreach ($this->items as $item) :
				$strHtml .= '<li><a href="' . JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)) . '" title="'.$item->title.'" ><span>'.$item->title.'</span></a></li>';
			endforeach;
			$strHtml .= '</ul></div>';
			
			
			echo $strHtml;
		elseif($this->escape($obj->category_title) == "Memória do Legislativo"):
			echo "<ul class='memoria'>";
			foreach ($this->items as $item) :
				$images  = json_decode($item->images);
		
				echo "<li>" ?>
				<img 
				<?php if ($images->image_intro_caption):
					echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
				endif; ?>
				src="<?php echo htmlspecialchars($images->image_intro); ?>"  />
				
				
				
		<?php 		echo "<span><b>".$item->title."</b></span><span>".$images->image_intro_caption."</span></li>";
			endforeach;
			
			echo "</ul>";
		else:		
			$strHtml .= 'class="camaraintinerante">';
			$strHtml .=  $this->category->description;
			$strHtml .= "<ul>";
			
			foreach ($this->items as $item) :
			
				list($ano, $mes, $dia) = explode('-', $item->publish_up);
				
				$dia = substr($dia, 0,2);
				$strHtml .= '<li>
						<a href="' . JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)) . '" title="'.$item->title.'" >'.$item->title.'</a>
					<span class="data">'.$dia.'/'.$mes.'/'.$ano.'</span>	
				</li>';
			
				
			endforeach;
			
			$strHtml .= "</ul>";
			$strHtml .="</div>";
			echo $strHtml;
		endif;
		
		
	endif;
	?>
	




<?php if (!empty($this->items)) : ?>
	<?php if (($this->params->def('show_pagination', 2) == 1  || ($this->params->get('show_pagination') == 2)) && ($this->pagination->pagesTotal > 1)) : ?>
	<div class="pagination">
		
		<div class="btnback">
			<a href="javascript:window.history.back()" title="Voltar à página anterior" ><img src="<?php echo JUri::base() ?>templates/cmmacae/img/btnBack.jpg" /></a>
		</div>
		
		<div class="pag">
		
		<?php echo $this->pagination->getPagesLinks(); ?>
		</div>
	</div>
	<?php endif; ?>

<?php  endif; ?>

</div>

<?php 

function getDateMyFormat($value) 
{
	$arrSemana = array('Domingo','Segunda-Feira','Terça-Feira','Quarta-Feira','Quinta-Feira','Sexta-Feira','Sábado');
	$arrMes = array('Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
	$dia = date("d", strtotime($value));
	$ano = date("Y", strtotime($value));
	$mes = date("m", strtotime($value));
	$semana = date("w", strtotime($value));

	$html = '';
	if(date('Y-m-d')==$value)
		$html .='Hoje - ';
	$html .= $arrSemana[$semana] . ' - ' . $dia . ' de ' . $arrMes[intval($mes)-1] . ' de ' . $ano;
	
	return $html;
}


 function getDateMyFormat2($value) {
   	
		$dia = date("d", strtotime($value));
	$ano = date("Y", strtotime($value));
	$mes = date("m", strtotime($value));
		return $dia.'/' .$mes."/".$ano;
	}
?>